import {createStore,combineReducers,applyMiddleware} from 'redux';   
// applyMiddleware:提供运用中间件的方法
import thunk from 'redux-thunk';         //中间件

// const loginReducer = (state={isLogin:false,list:[]},action)=>{
const loginReducer = (state={isLogin:false},action)=>{
    switch (action.type) {
        case 'login':
            return {...state,isLogin:true}
        default:
            return state;              //只有dispatch action可以改变store
    }
}

const homeReducer = (state={list:[1,2,3]},action)=>{
    switch (action.type) {
        case 'add_item':
            return {...state,list:[action.payload,...state.list]}
        default:
            return state;
    }
}

const rootReducer = combineReducers({
    // loginReducer,homeReducer
    login:loginReducer,
    home:homeReducer
})


const store = createStore(
    rootReducer,
    applyMiddleware(thunk)
)
export default store;